//
//  sendbasic.m
//  tcpoctest
//
//  Created by apple on 13-5-3.
//  Copyright (c) 2013年 gump. All rights reserved.
//

#import "sendbasic.h"

@implementation sendbasic

-(id)init
{
    self = [super init];
    if (self != nil) {
        sb = [[LogicSB alloc] init];
        
        mainIndex = ID_MI_HB;
        secIndex = ID_MI_HB;
        length = 0;
        data = 0;
        brelogin = false;
    }
    
    return self;
}

-(void)SetMainIndex:(int)im withSecIndex:(int)is
{
    mainIndex = im;
    secIndex = is;
}

-(void)ShowLog
{
    NS_LOG(@"send length %d mainindex %d secindex %d %@ \r\n"
                  ,length
                  ,mainIndex
                  ,secIndex
                  ,self);
}

-(void)initDataByLength:(int)il
{
    length = il;
    
    data = (char*)malloc(length);
    assert(data != nil);
    memset(data, 0, length);
    [sb initSB:data withLength:length];
    
    [LogicControl sharedLogicControl].icurSequence = getLocalSequence();
    [sb WriteInt:[LogicControl sharedLogicControl].icurSequence withNTT:NTT_SMALL2BIG];
    
    [sb WriteChar:mainIndex];
    [sb WriteChar:secIndex];

}

-(void)initDataUseCurSequence:(int)il
{
    length = il;
    
    data = (char*)malloc(length);
    assert(data != nil);
    memset(data, 0, length);
    [sb initSB:data withLength:length];
    
    [sb WriteInt:[LogicControl sharedLogicControl].icurSequence withNTT:NTT_SMALL2BIG];
    
    [sb WriteChar:mainIndex];
    [sb WriteChar:secIndex];
}

-(void)Package
{
    if (data == 0) {
        return;
    }
    
    [[netManager sharedNetManager] Package:data withLength:length];
    
    [sb cleanSB];
    
    [self ShowLog];

}

-(bool)CheckLogin
{
    bool blogin = false;
    
    if ([DataControl shareControl].blogin) {
        blogin = true;
    }
    else
    {
        blogin = false;
        if (brelogin) {
            [[netManager sharedNetManager] reloginBySend];
        }
    }
    
    return blogin;
}

-(void)setIsReLogin:(bool)bl
{
    brelogin = bl;
}

@end
